<?php
class ModelProductToCatalogSelect extends Model {

	//-------------------------------------------------------------------------//
	//Check duplicate couple product id and catalog id
	//-------------------------------------------------------------------------//
	public function checkDuplicatePC($product_id,$category_id) {
		$SQL = " SELECT COUNT(1) as total FROM product_to_category ";
		$SQL .= "  WHERE product_id ='".$product_id."'";
		$SQL .= "    AND category_id = '".$category_id."'";
		$query = $this->db->query($SQL);
		return $query->row['total'];

	}

	//-------------------------------------------------------------------------//
	// Get list category base on product_id
	//-------------------------------------------------------------------------//
	public function getListCategories($product_id) {
		$SQL = " SELECT category_id FROM product_to_category ";
		$SQL .= "  WHERE product_id ='".$product_id."'";
		$SQL .= "  ORDER BY category_id ASC ";
		$query = $this->db->query($SQL);
		$str = "";
		if(empty($query->rows) == false){
			foreach($query->rows as $data){
				$str .= "_".$data["category_id"];
			}
		}
		return substr($str,1);
	}
}
?>